{extend name="public/base"/}
{block name="body"}
<div class="main-box clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-left">
			<h2>{$meta_title}</h2>
		</div>
	</header>
	<div class="main-box-body clearfix">

		<form method="post" id="form" class="form form-horizontal" action="__URL__/Translation" enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-lg-2 control-label">选择文件</label>
				<div class="col-lg-2">
					<input type="file" name="file"  id="file" class="form-control">
					<div class="help-block" id="info"></div>
				</div>
				<label class="col-lg-2 control-label">翻译语言</label>
				<div class="col-lg-2">
					<select name="language" id="language" class="form-control">
						<option value="" >请选择</option>
						<option value="ug_CN" {if $language == "ug_CN"}selected{/if}>维文</option>
						<option value="kk_CN" {if $language == "kk_CN"}selected{/if}>哈文</option>
						<option value="zh_CN" {if $language == "zh_CN"}selected{/if}>中文</option>
						<option value="en_US" {if $language == "en_US"}selected{/if}>英文</option>
					</select>
				</div>
			</div>
			<div class="form-group" style="display: none" id="file_type_div">
				<label class="col-lg-2 control-label">选择导出类型</label>
				<div class="col-lg-2">
					<select name="file_type" class="form-control">
						<option value="mo">mo文件</option>
						<option value="po">po文件</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="col-lg-offset-2 col-lg-10">
					<button class="btn btn-success submit-btn" type="button" id="submit">读取文件</button>
					<button class="btn btn-success submit-btn" style="display: none" type="submit" id="translate">翻译保存</button>
				</div>
			</div>
		</form>

	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
$("#submit").click(function(){

	var formData = new FormData();
	formData.append("file",$("#file")[0].files[0]);
	formData.append("language",$("#language").val());
	$.ajax({
		url:"/admin/msgset/batchTranslation",
		data:formData,
		type:'post',
		async: false,
		cache: false,
		contentType: false,
		processData: false,
		dataType:'json',
		success:function(re){
			if(re.error){
				alert(re.msg);
			}else if(re.error==0){
				$("#info").html(re.msg);
				if(re.canTranslate){
					$("#translate").show();
					$("#file_type_div").show();
				}
			}
		}
	})
});

</script>
{/block}
